<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-tiles.tld" prefix="tiles"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/conf/tld/struts-bean.tld" prefix="bean"%>
<%@ page import="java.util.List"%>
<%@ page import="cn.agiledata.bank.common.util.Constant"%>
<%@ page import="cn.agiledata.bank.account.service.AccountSummary"%>
<%@ page import="cn.agiledata.bank.hibernateBean.SubAccount"%>
<%//String code = ImageUtil.getRandomNumber(4) ;
			//session.setAttribute(Constant.SESSION_VERIFY_CODE, code) ;
			String path = request.getContextPath();
			AccountSummary user = (AccountSummary) session
					.getAttribute(Constant.SESSION_ACCOUNT_SUMMARY);

			if (user == null) {

			%> 
 
<%}
			String subAccountKey = request.getParameter("key");
			SubAccount sub = user.getSubAccountById(subAccountKey);
			String acctId = sub.getAccount().getId().toString();
			String id = sub.getId().toString();
			String subId = sub.getAccountId();
			String subName = sub.getAccountName();
			String IVR = "是";
			if(sub.getIvrFlag().equals("N"))
			IVR = "否";
			String subRemark = sub.getRemark() == null ? "" : sub.getRemark();
			String detailFlag = sub.getDetailFlag() == null ? "" : sub.getDetailFlag();
			
			List list = user.getSubAccountList();
			StringBuffer accountId = new StringBuffer();
			StringBuffer accountName = new StringBuffer();
			if(list != null) {
				for(int i=0;i<list.size();i++) {
					SubAccount subAccount = (SubAccount)list.get(i);
					if(i != 0) {
						accountId.append(",").append(subAccount.getAccountId());
						accountName.append(",").append(subAccount.getAccountName());
					} else {
						accountId.append(subAccount.getAccountId());
						accountName.append(subAccount.getAccountName());			
					}
			
				}
			}
			String ids = accountId.toString();
			String names = accountName.toString();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title></title>
		<link href="<%=path%>/css/sinfo.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/style.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/newstyle.css" rel="stylesheet" type="text/css" />
		<link href="<%=path%>/css/common.css" rel="stylesheet" type="text/css" />
		<script type='text/javascript' src='<%=path%>/js/vnv/commonForManage.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/util.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/engine.js'></script>
		<script type='text/javascript' src='<%=path%>/dwr/interface/subAccountService.js'></script>

		<script language="JavaScript" type="text/JavaScript">
function submitProcess() {
		if(checkNecessaryInput(document.forms["0"]) && checkInputMaxlength(document.forms["0"]))
		{
		   document.forms["0"].submit();
		  }
}

/*
function isUniqueSubAccountId(obj) {
	var value = obj.value;
	var temp;
	var ids = "<%=ids%>".split(",");
	for(var i=0;i<ids.length;i++){	
		if(ids[i]==value && value != "" && ids[i] != <%=subId%>) {
			temp = false;
			break;
			
		}else{
			temp = true;
		}
	}
	return temp;
	
}
*/

function isUniqueSubAccountName(obj){
	var value = obj.value;
	var temp;
	var names = "<%=names%>".split(",");
	for(var i=0;i<names.length;i++){
		if(names[i]==value && value != "" && names[i] != <%=subName%>){
			temp = false;
		}else{
			temp = true;
		}
		if(temp==false) {
			alert("账户名称不能重复");document.getElementById("subAccountName").value="";document.getElementById("subAccountName").focus();
		}
	}
}

/*
function sure(){
	killSpace(document.getElementById("subAccountId"));
	if(!isUniqueSubAccountId(document.getElementById("subAccountId"))){
		alert("账户名称重复,请重新添加子账户!");
		history.back();
		
	}else{
		submitProcess();	
		
	}
}
*/

function load(){
	document.getElementById("subAccountName").focus();
}
</script>

	</head>

	<body >
		<div class="panel">
			<form action="modifySubAccount.do" method="post">
				<input type="hidden" name="subId" value="<%=subAccountKey%>" />
				<input type="hidden" name="id" value="<%=id%>"/>
    <table width="732" border="0" align="center" cellpadding="0" cellspacing="3" bgcolor="0EA2D6">
      <tr> 
        <td  bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td height="25" align="center" background="<%=path%>/images/new/blue_pic_01.gif"><strong><font color="#FFFFFF" style="font-size:12px">修改子账户</font></strong></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr> 
              <td height="8" ></td>
            </tr>
          </table>
          <table width="100%" border="0" cellspacing="0" cellpadding="8">
            <tr> 
              <td>
<table width="100%" align="center" cellpadding="3" cellspacing="1" class="form">
                  <tr bgcolor="#F0FAFD"> 
                    <th> 账户代码： </th>
                    <td> <input class="disedit" name="subAccountId" value="<%=subId%>" readonly="readonly"/>
                      *&nbsp;&nbsp;&nbsp;(账户代码由系统自动生成,用来标识账户) </td>
                  </tr>
                  <tr> 
                    <th> 子账户名称： </th>
                    <td> <input name="subAccountName" value="<%=subName%>" alt="账户名称" onblur="killSpace(this);isUniqueSubAccountName(this)" maxlength="32" />
                      *
                    </td>
                  </tr>
                  <tr bgcolor="#F0FAFD"> 
                    <th> Wap账户： </th>
                    <td> <bean:define id="detail" value="<%=detailFlag%>" /> <logic:empty name="detail"> 
                      <input type="radio" name="detailFlag" value="Y">
                      是 &nbsp; 
                      <input type="radio" name="detailFlag" value="N" checked>
                      否 </logic:empty> <logic:notEmpty name="detail"> <logic:equal name="detail" value="Y"> 
                      <input type="radio" name="detailFlag" value="Y" checked>
                      是 &nbsp; 
                      <input type="radio" name="detailFlag" value="N">
                      否 </logic:equal> <logic:equal name="detail" value="N"> 
                      <input type="radio" name="detailFlag" value="Y">
                      是 &nbsp; 
                      <input type="radio" name="detailFlag" value="N" checked>
                      否 </logic:equal> </logic:notEmpty> </td>
                  </tr>
                  <logic:equal name="sessionAccountSummary" property="account.accountType" value="A">
                  <tr>
                  <th>IVR账户：</th>
                  <td><%=IVR %>&nbsp;&nbsp;&nbsp;
                 <a href="<%=path%>/page/myspace/newIVR.do?accountId=<%=acctId %>"> 点击这里修改IVR付款子账户</a></td>
                  </tr>
                 </logic:equal>
                  <tr> 
                    <th> 备注： </th>
                    <td colspan="2"> <textarea rows="5" name="subAccountRemark" title="maxlength:255;title:备注"><%=subRemark%></textarea>
                    </td>
                  </tr>
                  <tr> 
                    <td colspan="2"> <hr noshade="noshade" size="2" color="#0EA2D6" /> 
                    </td>
                  </tr>
                  <tr>
                    <td colspan="2" style="text-align:right;"> 
                    	<img  name="sure" style="cursor:pointer; margin-right:5px;" onclick="submitProcess();" src="<%=path%>/images/new/ok_button.gif"  /> 
                    	<img  style="cursor:pointer; margin-right:5px;" src="<%=path%>/images/new/return.gif" onclick="location.href='subAccount.do'" />
                    </td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
    </form>
		</div>
	</body>
</html>
